package ch.zbw.pra.sysventory.presentation.panels;

import java.util.List;

import ch.zbw.pra.sysventory.application.controller.PrinterController;
import ch.zbw.pra.sysventory.model.Printer;

import com.vaadin.ui.Alignment;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;

/**
 * Painted das PrintersArchivePanel
 * 
 * @author Ralph Koster
 */

public class PrintersArchivePanel extends VerticalLayout {

	private static final long serialVersionUID = 1L;
	private PrinterController printerController;
	private Table printersTable;
	
	public PrintersArchivePanel(){
		this.printersTable = new Table("Drucker im Netzwerk:");
		this.printerController = new PrinterController();
		paint();
		loadPrinters();
	}
	
	private void paint() {
		this.setCaption("Drucker");
		this.setStyleName("printersArchivePanel");
		printersTable.setStyleName("table");
		printersTable.addContainerProperty("Drucker Name", String.class, null);
		printersTable.addContainerProperty("Drucker Treiber", String.class, null);
		printersTable.addContainerProperty("Drucker Version", String.class, null);
		this.addComponent(printersTable);
		this.setComponentAlignment(printersTable, Alignment.MIDDLE_CENTER);
	}

	private void loadPrinters() {
		printersTable.removeAllItems();
		List<Printer> printers = printerController.loadPrinters();
		for(Printer printer : printers) {
			int printerId = printer.getPrinterId();
			String printerName= printer.getNamePrinter();
			String printerDriver = printer.getDriverNamePrinter();
			String printerDriverVersion = printer.getDriverVersionPrinter();
			printersTable.addItem(new Object[] {
				    printerName,printerDriver,printerDriverVersion},printerId);
		}
			
	}

	public void updatePrintersArchivePanel() {
		loadPrinters();
	}
}
